package com.example.springdemo02.custom;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 自定义事件监听器，监听{@link CustomEvent}
 */

@SuppressWarnings("unused")
@Component
public class CustomListener implements ApplicationListener<CustomEvent> {
    private static final Logger logger= LoggerFactory.getLogger(CustomListener.class);

    @Override
    public void onApplicationEvent(CustomEvent customEvent) {
        logger.info("事件监听器获取到 NoticeEvent,睡眠当前线程3秒...");
        try {
            Thread.sleep(3000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        logger.info("CustomEvent的message属性是:{}",customEvent.getMessage());
    }
}
